package com.boboPlanet.user.mq.peoducerBean;

import com.boboPlanet.user.mq.PlanetMiddleMqEnum;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2023/2/18
 **/
@Configuration
public class XxlJobRabbitMqConfig {

    public XxlJobRabbitMqConfig(){}

    @Bean
    public Queue xxlSendUserStateQueue(){
        return new Queue(PlanetMiddleMqEnum.CHANGE_USER_STATE_MQ.getQueue(),true);
    }

    @Bean
    TopicExchange xxlSendUserStateExchange() {
        return new TopicExchange(PlanetMiddleMqEnum.CHANGE_USER_STATE_MQ.getExchange(),true,false);
    }

    /**
     * todo:路由绑定交换机(routing-key)
     * @return Binding
     */
    @Bean
    Binding xxlSendUserStateBindingExchange() {
        return BindingBuilder.bind(this.xxlSendUserStateQueue())
                .to(this.xxlSendUserStateExchange())
                .with(PlanetMiddleMqEnum.CHANGE_USER_STATE_MQ.getRoutingKey());
    }

}
